# Richard Hundhausen
# richard@accentient.com
# http://blog.hundhausen.com

#**************************************************************
# Starting PowerShell
#**************************************************************

powershell

powershell -?

$host

#**************************************************************
# Similar to Windows command shell
#**************************************************************

dir

dir c:\Windows\*.*

dir c:\Windows\*.* | findstr /I "bmp"

#**************************************************************
# Take a tour
#**************************************************************

# C:\WINDOWS\system32\windowspowershell\v1.0

cd $pshome

dir

dir *.rtf

gettingstarted.rtf

userguide.rtf

# help files
dir *.txt

 
#**************************************************************
# Basic Cmdlets (verb-noun)
#**************************************************************

get-command

get-command -verb get

# other common verbs: add, clear, format, get, import, invoke,
#  new, out, remove, set, start, stop, update, write

get-command -noun service

get-process

get-process explorer

get-process s*

get-service *er*

get-service er*

get-eventlog application

get-command *.exe

get-wmiobject win32_bios -computername d820


#**************************************************************
# Help!
#**************************************************************

get-help

get-help get-eventlog

get-help get-eventlog -detailed

get-help get-eventlog -examples

get-help get-eventlog -full

help get-eventlog

man get-eventlog

get-help about_wildcard

# Tab completion
get-h <tab><tab> ...

#**************************************************************
# Services
#**************************************************************

get-service w32time

stop-service w32time

start-service w32time

get-service w32time | format-list

get-service w32time | format-list -property *

get-service w32time | format-list -property name

get-service | findstr "SQL"

get-service | findstr /I "SQL"

#**************************************************************
# Piping
#**************************************************************

get-process

get-process | findstr "csrss"

get-process | where {$_.handlecount -gt 400}

get-process | where {$_.handlecount -gt 400} | sort-object handles

get-process | get_member

cd c:\windows

get-childitem | where {($_.lastwritetime).dayofweek -eq "Tuesday"}
 
#**************************************************************
# Get-Member
#**************************************************************

get-date

get-date | get_member

get-date | get_member datetime

get-date | get_member datetime | format-list

(get-date).day

(get-date).dayofweek

(get-date).tolongdatestring

(get-date).tolongdatestring()

#

get-service alerter

get-service alerter | format-list -property canshutdown

get-service alerter | format-list -property *

get-service | format-table -property name, canshutdown

get-service | format-table -property name, canshutdown -autosize

get-process | sort-object company

get-process | sort company | format-table company, name, description, handles

get-process | sort company | format-table -group company name, description, handles

#**************************************************************
# Out cmd-lets
#**************************************************************

get-service

get-service | out-host -paging

get-service | format-list | out-host -paging

#**************************************************************
# Scripts (need to be in the powershell first)
#**************************************************************

c:\demo\test.ps1

get-help about_signing

set-executionpolicy unrestricted

c:\demo\test.ps1

#**************************************************************
# Aliases
#**************************************************************

get-alias

get-alias | where-object {$_.definition -eq "set-location"}

set-location alias:

get-childitem

get-childitem alias:

get-alias | where-object {$_.definition -eq "get-childitem"}

set-alias np c:\windows\notepad.exe

remove-item alias:ls

# aliases pre-setup for you (via profile)

cd $pshome

cd examples

dir

notepad profile.ps1
 
#**************************************************************
# Functions - calling aliases w/ parameters
#**************************************************************

notepad c:\boot.ini

# Doesn't work:
set-alias npbootini c:\windows\notepad.exe c:\boot.ini

# Instead:
function bootini {notepad c:\boot.ini}

#**************************************************************
# Environment variables
#**************************************************************

$env:path

$env:path += ";c:\demo"

test.ps1

#**************************************************************
# Navigating data stores
#**************************************************************

# List the PowerShell drives (providers)

get-psdrive

# hard drives: set-location (cd), get-children (dir or ls)

cd c:\windows

cd $home

cd $pshome

cd c:\demo

new-item -path . -name test.xml -type "file" -value "<xml>data</xml>"

dir

copy-item test.xml -destination test2.xml

dir

remove-item test.xml

dir

move-item test2.xml -destination c:\test.xml

dir

cd c:\

dir

# registry

cd hklm:

dir

cd software

dir

dir -recurse

cd hklm:

cd software\microsoft\powershell\1\ShellIds\Microsoft.PowerShell

dir

get-itemproperty -path . -name executionpolicy

# certificates

cd cert:

dir

cd currentuser

dir

cd authroot

dir

get-childitem F88015D3F98479E1DA553D24FD42BA3F43886AEF | format-list -property *

# environment

cd env:

dir

#**************************************************************
# Create your own powershell drive
#**************************************************************

new-psdrive -name MyDocs -psprovider FileSystem -root "$home\My Documents"

get-psdrive

cd mydocs:

dir

get-psprovider

get-help filesystem

#**************************************************************
# Fun Scripts
#**************************************************************

# Prebuild demos

c:\demo\new-guid.ps1

c:\demo\get-title.ps1

c:\demo\set-title.ps1 "I love PowerShell!"

c:\demo\get-username.ps1

c:\demo\n.ps1

c:\demo\get-diskusage.ps1

c:\demo\get-calendar.ps1

c:\demo\view-object.ps1 (gi c:\demo\test.ps1)

# May need to edit these still

c:\demo\smo-show all databases.ps1

c:\demo\smo-script aw tables.ps1

c:\demo\smo-execute.ps1

#**************************************************************
# Best for last
#**************************************************************

c:\demo\psinvaders\psinvaders.ps1
